import moment from 'moment';
export const formatHHMMSS =(vl)=> {
    var hh = parseInt(vl/1000/3600);
    var mm = parseInt(vl/1000%3600/60);
    var ss = parseInt(vl/1000%60);
    if(hh<10){ 
        hh = "0"+hh;
    }
    if(mm<10){ 
        mm = "0"+mm;
    }
    if(ss<10){ 
        ss = "0"+ss;
    }
    return hh + ":"+ mm + ":" + ss;
}


export const formatDate =(time , type )=> {
  time = moment(time);
  let year = time.get('years'),
    month = time.get('months')+1 < 10 ? `0${time.get('months')+1}` : time.get('months')+1,
    day = time.get('date') < 10 ? `0${time.get('date')}` : time.get('date'),
    hours = time.get('hours') < 10 ? `0${time.get('hours')}` : time.get('hours'),
    mins = time.get('minutes') < 10 ? `0${time.get('minutes')}` : time.get('minutes'),
    ss = time.get('seconds') < 10 ? `0${time.get('seconds')}` : time.get('seconds');

    if(type=="hhmmss") {
        return `${hours}:${mins}:${ss}`;
    }
    if(type=='YYMMDD') {
        return `${year}-${month}-${day}`;
    }
  return `${year}-${month}-${day} ${hours}:${mins}:${ss}`;
}
//对象排序
export const compare = function (prop) {
    return function (obj1, obj2) {
        var val1 = obj1[prop];
        var val2 = obj2[prop];if (val1 < val2) {
            return -1;
        } else if (val1 > val2) {
            return 1;
        } else {
            return 0;
        }            
    } 
}